<template>
  <div class="mui-pages" style="background-color: #fff;">
    <header class="mui-bar mui-bar-nav">
      <div class="header-common-title flex-justify-start">
        <a @click="fn.back()" href="javascript:void(0)"><img class="back-btn" src="../../../../static/images/back.png"></a>
        <div class="header-search flex-center">心得体会</div>
      </div>
    </header>
    <div class="mui-scroll-wrapper mui-page-content">
      <div class="mui-scroll">
        <div class="statistics-header">
          <h4 v-if="data.dealContent && false">{{scheduleDetail.insPartyMeetingResponseModel.subject}}心得</h4>
          <div class="experience-worlds" v-html="data.dealContent">
          </div>
          <p class="record-item-title flex-justify-start">心得体会附件：</p>
          <ul class="list-item mui-content-padded flex-justify-start" v-if="data.dealFiles">
            <li class="enclosure-upload" v-for="(data,index) in getFilePath(data.dealFiles)" v-if="data" :key="data.fileId">
              <img v-if="isImage(data.fileName)" class="enclosure-upload-file" :src="data.url" @click="showImagePreview(data.url)" />
              <img v-if="!isImage(data.fileName)" class="enclosure-upload-file" src="../../../../static/images/up_document.png"  @click="downLoadFile(data)" />
              <p class="mui-ellipsis">{{data.fileName}}</p>
            </li>
          </ul>
          <div class="no-data" v-if="!data.dealFiles || data.dealFiles.length <= 0">
            <img src="../../../../static/images/no_data.png" alt="">
            <p>暂无数据</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import footerbar from '../common/footerbar.vue'
  import tools from '@/utils/tools'
  import loginService from '@/service/loginService'
  import scheduleSign from '@/components/work/schedule/scheduleSign'
  import api from '@/common/config/api'

  export default {
    components: {
      footerbar, scheduleSign
    },
    name: '',
    data () {
      return {
        fn: tools,
        data: {},
        tabIndex: 0,
        options: {
          pullUpLoad: true,
          scrollbar: false
        },
        objectsName: '',
        swipeData: [],
        infinite: true,
        userInfo: this.$store.state.userInfo,
        isShowMoreBtn: false,
        scheduleDetail: {},
        pageIndex: 0
      }
    },
    created () {
      this.data = this.$store.state.otherExperience
      this.scheduleDetail = this.$store.state.scheduleDetail
    },
    methods: {
      showMoreBtn () {
        this.isShowMoreBtn = true
      },
      showDeal (item) {
        if (!item.dealFlag) {
          return false
        }
        this.$router.push({name: 'otherExperience'})
      },
      // 编辑会议
      edit (data) {
        this.$router.push({name: 'scheduleDetail'})
      },
      detail (data) {
        this.$store.state.scheduleData = data
        this.$router.push({name: 'scheduleDetail'})
      },
      onPullingUp () {
        console.log('onPullingUp')
        this.loadData()
      },
      openSignList (signSatus) {
        this.$router.push({'path': `/scheduleSignPeople/${signSatus}`})
      },
      // 开始签到
      startSign (meetingId) {
        loginService.startPartyMemberSign(meetingId).then((res) => {
          this.$router.push({'path': `/scheduleSign/${meetingId}`})
          if (res.code === 200) {
          }
        })
      },
      loadData () {
        let pkId = this.$route.params.pkId
        loginService.getPubsherMeetingInfoByPkId(pkId).then((res) => {
          if (res.code !== 200) {
            return tools.tip(res.describe === '未查询到资源' ? '已无更多数据' : res.describe)
          }
          this.$store.state.scheduleDetail = this.data = res.data
        })
      },
      getFilePath (arr) {
        if (typeof arr === 'string') {
          try {
            arr = JSON.parse(arr)
          } catch (e) {
            console.error(e)
            arr = []
          }
        }
        console.log(arr)
        arr.map((v, i) => {
          if (!v) {
            arr.splice(i, 1)
          } else {
            v.url = api.downLoadFile + v.fileId
            return v
          }
        })
        return arr
      },
      isImage (fileName) {
        let arrExt = fileName.split('.')
        return 'PNG,JPG,JPEG,BMP,GIF'.split(',').indexOf(arrExt[arrExt.length - 1].toUpperCase()) > -1
      },
      showImagePreview (url) {
        if (url.length < 1) {
          return false
        }
        let imgs = [url]
        this.$createImagePreview({
          initialIndex: 0,
          imgs: imgs
        }, (h) => {
          return h('div', {
            class: {
              'image-preview-custom-header': false
            },
            slot: 'header'
          }, '')
        }).show()
      },
    },
    watch: {
      tabIndex (newValue) {
        this.$store.state.recordDetailtabIndex = newValue
      }
    }
  }
</script>
